package leetcode.题库.栈;

import java.util.Stack;

/**
 * description: 最小栈
 *
 * @author 颜真明
 * @date 2024/3/27  9:57
 */
public class Solution155 {

    // 普通栈
    Stack<Integer> stack;
    // 最小栈
    Stack<Integer> minStack;

    public Solution155() {
        stack = new Stack<>();
        minStack = new Stack<>();
        minStack.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        stack.push(val);
        if(val < minStack.peek()) {
            minStack.push(val);
        } else {
            minStack.push(minStack.peek());
        }
    }

    public void pop() {
        stack.pop();
        minStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }

}
